{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3b0ad128-a99b-44e2-8fcd-e0d517496f38",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 0.652031    0.04643589 -0.40187663 ... -0.6665882  -0.76702946\n",
      "    0.29452622]\n",
      "  [ 0.3748061   0.63287777 -0.1933821  ... -0.1571283  -0.03689617\n",
      "   -0.05258662]\n",
      "  [-0.0353355  -0.04532271 -0.02375055 ...  0.03203112 -0.05350752\n",
      "   -0.19852895]\n",
      "  ...\n",
      "  [-0.14501537  0.7277831   0.23639265 ...  0.22381197  0.29034108\n",
      "    0.3354566 ]\n",
      "  [-0.5548637   0.3631793   0.5244673  ...  0.10587544  0.12167144\n",
      "    0.02036233]\n",
      "  [ 0.53484774  0.12817204  0.08042635 ... -0.11877135 -0.06255031\n",
      "   -0.05381754]]]\n",
      "[[[ 0.652031    0.04643589 -0.40187663 ... -0.6665882  -0.76702946\n",
      "    0.29452622]\n",
      "  [ 0.3748061   0.63287777 -0.1933821  ... -0.1571283  -0.03689617\n",
      "   -0.05258662]\n",
      "  [-0.0353355  -0.04532271 -0.02375055 ...  0.03203112 -0.05350752\n",
      "   -0.19852895]\n",
      "  ...\n",
      "  [-0.14501537  0.7277831   0.23639265 ...  0.22381197  0.29034108\n",
      "    0.3354566 ]\n",
      "  [-0.5548637   0.3631793   0.5244673  ...  0.10587544  0.12167144\n",
      "    0.02036233]\n",
      "  [ 0.53484774  0.12817204  0.08042635 ... -0.11877135 -0.06255031\n",
      "   -0.05381754]]]\n",
      "layer_0:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_1:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_2:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_3:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_4:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_5:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_6:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_7:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_8:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_9:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_10:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_11:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_12:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_13:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_14:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_15:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_16:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_17:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_18:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_19:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_20:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_21:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_22:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_23:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_24:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_25:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_26:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n",
      "layer_27:\n",
      "Input shape: (1, 267, 1024)\n",
      "Output shape: (1, 267, 1024)\n"
     ]
    }
   ],
   "source": [
    "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
    "import torch\n",
    "\n",
    "# 初始化模型\n",
    "model_id = '/model/ModelScope/Qwen/Qwen3-0.6B'\n",
    "model = AutoModelForCausalLM.from_pretrained(model_id, device_map=\"auto\")\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
    "\n",
    "\n",
    "# 用于存储每一层的输入和输出\n",
    "activations = {}\n",
    "\n",
    "# 定义钩子函数\n",
    "def get_activation(name):\n",
    "    def hook(module, input, output):\n",
    "        hidden_states = output[0]\n",
    "        # print(hidden_states)\n",
    "        activations[name] = {\n",
    "            'input': input[0].detach().cpu().numpy(),\n",
    "            'output': output[0].detach().cpu().numpy()\n",
    "        }\n",
    "    return hook\n",
    "\n",
    "# 为每一层注册钩子\n",
    "for i, layer in enumerate(model.model.layers):\n",
    "    layer.register_forward_hook(get_activation(f'layer_{i}'))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "3700b53e-17b0-416f-a391-a9f7458c2fc4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[ 0.652031    0.04643589 -0.40187663 ... -0.6665882  -0.76702946\n",
      "    0.29452622]\n",
      "  [-0.11009285  0.6334653   0.33951125 ... -0.17202726 -0.24047822\n",
      "   -0.21551886]\n",
      "  [-0.39777544  1.131537   -0.25907117 ... -0.4139713   0.10798842\n",
      "    0.05831181]\n",
      "  ...\n",
      "  [-0.13876776  0.7294401   0.24299505 ...  0.22100824  0.28839892\n",
      "    0.33561906]\n",
      "  [-0.54995763  0.36405438  0.5262048  ...  0.10363967  0.12153722\n",
      "    0.02216986]\n",
      "  [ 0.54202735  0.13096127  0.09284829 ... -0.11744348 -0.0588733\n",
      "   -0.06595493]]]\n",
      "[[[ 0.652031    0.04643589 -0.40187663 ... -0.6665882  -0.76702946\n",
      "    0.29452622]\n",
      "  [-0.11009285  0.6334653   0.33951125 ... -0.17202726 -0.24047822\n",
      "   -0.21551886]\n",
      "  [-0.39777544  1.131537   -0.25907117 ... -0.4139713   0.10798842\n",
      "    0.05831181]\n",
      "  ...\n",
      "  [-0.13876776  0.7294401   0.24299505 ...  0.22100824  0.28839892\n",
      "    0.33561906]\n",
      "  [-0.54995763  0.36405438  0.5262048  ...  0.10363967  0.12153722\n",
      "    0.02216986]\n",
      "  [ 0.54202735  0.13096127  0.09284829 ... -0.11744348 -0.0588733\n",
      "   -0.06595493]]]\n",
      "layer_0:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_1:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_2:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_3:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_4:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_5:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_6:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_7:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_8:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_9:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_10:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_11:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_12:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_13:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_14:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_15:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_16:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_17:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_18:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_19:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_20:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_21:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_22:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_23:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_24:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_25:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_26:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n",
      "layer_27:\n",
      "Input shape: (1, 261, 1024)\n",
      "Output shape: (1, 261, 1024)\n"
     ]
    }
   ],
   "source": [
    "# 输入数据\n",
    "\n",
    "# 输入文本\n",
    "input_text = \"\"\"\n",
    "Large language models (LLMs) show excellent performance but are compute- and memoryintensive. Quantization can reduce memory and\n",
    "accelerate inference. However, existing methods cannot maintain accuracy and hardware efficiency at the same time. \n",
    "We propose SmoothQuant, a training-free, accuracy-preserving, and generalpurpose post-training quantization (PTQ) solution\n",
    "to enable 8-bit weight, 8-bit activation (W8A8) quantization for LLMs. Based on the fact that\n",
    "weights are easy to quantize while activations are not, SmoothQuant smooths the activation outliers\n",
    "by offline migrating the quantization difficulty from activations to weights with a mathematically equivalent transformation. \n",
    "SmoothQuant enables an INT8 quantization of both weights and activations for all the matrix multiplications in\n",
    "LLMs, including OPT, BLOOM, GLM, MT-NLG, Llama-1/2, Falcon, Mistral, and Mixtral models.\n",
    "We demonstrate up to 1.56× speedup and 2× memory reduction for LLMs with negligible loss in accuracy. \n",
    "SmoothQuant enables serving 530B LLM within a single node. Our work offers a turn-key solution that reduces hardware costs and democratizes LLMs.\n",
    "\"\"\"\n",
    "\n",
    "# input_text = \"\"\"\n",
    "# Hello, how are you? \n",
    "# \"\"\"\n",
    "    \n",
    "inputs = tokenizer(input_text, return_tensors='pt')\n",
    "\n",
    "# 前向传播\n",
    "model(inputs['input_ids'].cuda())\n",
    "\n",
    "\n",
    "\n",
    "print(activations['layer_1']['output'])\n",
    "print(activations['layer_2']['input'])\n",
    "\n",
    "\n",
    "# 查看激活值\n",
    "for name, activation in activations.items():\n",
    "    print(f\"{name}:\")\n",
    "    print(f\"Input shape: {activation['input'].shape}\")\n",
    "    print(f\"Output shape: {activation['output'].shape}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "51ba4c6a-9206-490b-a3e5-ea3536996d38",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(261, 1024)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "activate_origin = activations['layer_26']['output'].reshape(-1,1024)\n",
    "activate_origin.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d0a97f9-7470-4959-9b3b-9708e982ca48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "268.81011962890625"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "activate_strip = 2\n",
    "token_strip = 1\n",
    "weights = activate_origin[::token_strip, ::activate_strip]\n",
    "weights.max().item()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "7940fbd6-8751-4f64-9150-58beadb9717f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  0   1   2 ... 509 510 511]\n",
      " [  0   1   2 ... 509 510 511]\n",
      " [  0   1   2 ... 509 510 511]\n",
      " ...\n",
      " [  0   1   2 ... 509 510 511]\n",
      " [  0   1   2 ... 509 510 511]\n",
      " [  0   1   2 ... 509 510 511]] [[  0   0   0 ...   0   0   0]\n",
      " [  1   1   1 ...   1   1   1]\n",
      " [  2   2   2 ...   2   2   2]\n",
      " ...\n",
      " [258 258 258 ... 258 258 258]\n",
      " [259 259 259 ... 259 259 259]\n",
      " [260 260 260 ... 260 260 260]]\n",
      "[[0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " ...\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]\n",
      " [0. 0. 0. ... 0. 0. 0.]]\n",
      "执行时间：197.124447 秒\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import time\n",
    "import matplotlib\n",
    "import random\n",
    "\n",
    "matplotlib.use('Agg')\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.ioff()\n",
    "\n",
    "plt.rcParams['path.simplify'] = True\n",
    "plt.rcParams['path.simplify_threshold'] = 0.1\n",
    "\n",
    "# 创建行列索引网格\n",
    "rows, cols = weights.shape\n",
    "\n",
    "x = np.arange(0, cols)  # 列索引作为x轴\n",
    "y = np.arange(0, rows)  # 行索引作为y轴\n",
    "\n",
    "X, Y = np.meshgrid(x, y)  # 生成坐标网格\n",
    "\n",
    "print(X, Y)\n",
    "\n",
    "# 创建三维图形\n",
    "fig = plt.figure(figsize=(10, 8))\n",
    "ax = fig.add_subplot(111, projection='3d')\n",
    "\n",
    "bottom = np.zeros_like(weights)\n",
    "print(bottom)\n",
    "\n",
    "# colors = [\"blue\", \"cornflowerblue\", \"mediumturquoise\", \"goldenrod\"] * int(rows * cols / 4)\n",
    "\n",
    "colors_element=[\"red\", \"yellow\", \"blue\", \"green\", \"orange\"]\n",
    "colors=[]\n",
    "\n",
    "# for i in range(0, rows):\n",
    "#     colors.extend(random.sample(colors_element, 1)*cols)\n",
    "\n",
    "colors_element=[\"red\", \"yellow\", \"blue\", \"green\", \"orange\"]\n",
    "colors=[]\n",
    "temp = random.choices(colors_element, k=cols)\n",
    "for i in range(0, rows):\n",
    "    colors.extend(temp)\n",
    "\n",
    "colors_np =np.array(colors)\n",
    "# print(colors_np)\n",
    "\n",
    "ax.bar3d(\n",
    "    X.ravel(), Y.ravel(), bottom.ravel(), 0.05, 0.05, np.abs(weights).ravel(),\n",
    "    color=colors_np,\n",
    "    shade=True,\n",
    ")\n",
    "\n",
    "# 添加标签和标题\n",
    "ax.set_xlabel('channel', labelpad=15)\n",
    "ax.set_ylabel('token', labelpad=15)\n",
    "ax.set_zlabel('Value', labelpad=10)\n",
    "ax.set_title('Activate Tensor', pad=20)\n",
    "\n",
    "start = time.perf_counter()\n",
    "plt.savefig(\"demo_avtivate.pdf\", dpi=100)\n",
    "end = time.perf_counter()\n",
    "exe_time = end - start\n",
    "print(f\"执行时间：{exe_time:.6f} 秒\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "0c654c1b-eff9-4217-aecf-c7806987f612",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "512 8\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['yellow',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'green',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'red',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'red',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'red',\n",
       " 'green',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'orange',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'red',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'green',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'green',\n",
       " 'green',\n",
       " 'green',\n",
       " 'orange',\n",
       " 'orange',\n",
       " 'blue',\n",
       " 'yellow',\n",
       " 'yellow',\n",
       " 'red',\n",
       " 'red',\n",
       " 'yellow',\n",
       " 'orange',\n",
       " 'green',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " 'red',\n",
       " 'blue',\n",
       " ...]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(cols,rows)\n",
    "colors_element=[\"red\", \"yellow\", \"blue\", \"green\", \"orange\"]\n",
    "colors=[]\n",
    "for i in range(0, rows):\n",
    "    # colors.extend(random.sample(colors_element, 1)*cols)\n",
    "    colors.extend(random.choices(colors_element, k=cols))\n",
    "colors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c043014f-3c7d-4dec-afd1-8f8898c9f2ef",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
